package org.csu.jpetstore_cms.controller;
import lombok.extern.slf4j.Slf4j;
import org.csu.jpetstore_cms.pojo.Account;
import org.csu.jpetstore_cms.pojo.Result;
import org.csu.jpetstore_cms.service.AccountService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import java.util.List;

@Slf4j
@RequestMapping("/accounts")
@RestController
public class AccountController {

    @Autowired
    private AccountService accountService;

    @GetMapping("/accountInfo")
    public Result GetAccount(String userid){
        Account account = accountService.findByID(userid);
        return Result.success(account);
    }

    @GetMapping("/allAccountInfo")
    public Result GetAllAccount(){
        List<Account> accountList = accountService.findAll();
        System.out.println(accountList);
        return Result.success(accountList);
    }
    @GetMapping("/page")//user
    public Result findPage(@RequestParam Integer pageNum,@RequestParam Integer pageSize){
        pageNum=(pageNum-1)*pageSize;
        List<Account> accountList1=accountService.findByPage(pageNum,pageSize);
        System.out.println(accountList1);
        return  Result.success(accountList1);
    }
    @PostMapping("/accountInsert")
    public void insertAccount(){

    }
    @GetMapping("/accountSearch")
    public Result searchaccount(@RequestParam String userid1,@RequestParam String email1,@RequestParam String addr11){
//        List<Account> accountList2=
//        return Result.success(accountList2);
        return Result.success("sucess");
    }
}
